/*
 * @ProjectName: 编程学习
 * @Copyright:   2020 HangZhou Yiyuery Dev, Ltd. All Right Reserved.
 * @address:     微信搜索公众号「架构探险之道」获取更多资源。
 * @date:        2020/9/6 10:49 上午
 * @blog:         https://yiyuery.blog.csdn.net/
 * @description: 本内容仅限于编程技术学习使用，转发请注明出处.
 */
package pub.dsb.api.orm;

import org.junit.Test;
import org.springframework.util.Base64Utils;
import pub.dsb.framework.boot.security.decrypt.DesCbcAssistant;
import pub.dsb.framework.boot.security.decrypt.RsaAssistant;

import java.net.URI;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.security.KeyPair;
import java.util.Random;

/**
 * <p>
 *
 * </p>
 *
 * @author Yiyuery
 * @date 2020/9/6 10:49 上午
 */
public class SecuritySupport {

    private static String rsaPubKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtRofNeIZ719pzib6f57OlTRVtzH5BTnIRjdkAPm21HRaiu1DzqJlfVUxyvLhyfevzlN0zv+iUnrOJlNniycyM+NCpCnPpdnzNFPb/ZaPwi8r0klQN2SY5eTUQAAygtaFiD2P1Ojc4iXSZeQf6cDEhr45o1y9LoagMRwlSxmHrhXcP+7IB4gWNOQXDgj7yCaheJez+ICm8qxSqINkSjZKPgB+lchoOH4o17rHsjSzq2eNcxAjtIxL1aIchwM6Pvxm83hsti59jHLycHIxHnK1a0RJBBAeS2Ev7CoQ9Fa+/jYe5D7LEUersNfVGImjQzHJFSKO705qt8Ympnk2fvxvywIDAQAB";
    private static String rsaPriKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC1Gh814hnvX2nOJvp/ns6VNFW3MfkFOchGN2QA+bbUdFqK7UPOomV9VTHK8uHJ96/OU3TO/6JSes4mU2eLJzIz40KkKc+l2fM0U9v9lo/CLyvSSVA3ZJjl5NRAADKC1oWIPY/U6NziJdJl5B/pwMSGvjmjXL0uhqAxHCVLGYeuFdw/7sgHiBY05BcOCPvIJqF4l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IXGpwnrjfh5K2XklhYKdBpXEYnEpYp8aYiQqUqR9oWZK3W1VzhpR7LMrood0yhc8EBt7h/1OTARlc6A8Q0ihFGkkfEpW9RkxY5utErQw3GPjlsGQU3Q8juw/R+xcEY/L/WS5AoGAT4w1awT1xnMPbo0JwYTP+LTDUGUT1phH6d0fOCYE/Jjt7EB7+VMdANpddv6l29hzWA69qYfEqkvNRwhPYbjXFk4z+sLD7prc/MUdjeJ27+vTg1yXB0PigQpDhmoNNSq2TLgdhrBJxiiBTl3JTW+3bA9Os60LW4p2KXbCsBHHCIk=";

    /**
     * rsa 密钥对生成
     * @throws Exception
     */
    @Test
    public void createKeyPair() throws Exception {
        KeyPair keyPair = RsaAssistant.generateKeyPair();
        System.out.println(Base64Utils.encodeToString(keyPair.getPublic().getEncoded()));
        System.out.println(Base64Utils.encodeToString((keyPair.getPrivate().getEncoded())));
    }

    /**
     * RSA 加解密测试
     * @throws Exception
     */
    @Test
    public void decryptTest() throws Exception {
        String encrypt = RsaAssistant.encrypt("架构探险之道@Yiyuery", rsaPubKey);
        System.out.println(RsaAssistant.decrypt(encrypt,rsaPriKey));
    }


    @Test
    public void urlEncode(){
        System.out.println(URLEncoder.encode("Ojn4Z8vgmFqUB6xOFoz1fOJz+TuoviPceUtRLsBOYpL7xcpv/UlLsF+scDU+8JEIMM2kOVybcTHQ55jgcvhU1H6nKSKlkawTP82mHO8FiRXX9YTg/eZd3di2/VLVp8WM8EwxabFmZCuyaPNpkhLk94TcM2RDffdtw3PB4PDrKrM1EXDKWEtLSMAuKuECfBo8vSkk3Zl7dbXkfSyI0ritLCXaNoIPdnB8BTjosaC7/RXtlxvUxNG3jT2nLRoQcWWODGxDmX6P/HaHvs1WAUTAZ5GG+maDtVxK2lSQFPw2lYzAlD62CeaZST2RKXuuNK+SvIHUPMR9SpqlR9oeYZcxAw=="));
    }


    @Test
    public void desKey(){
        System.out.println(new DesCbcAssistant("DES").generatorRandomKey(200));
    }
}
